# -*- coding:utf-8 -*-
#! /usr/bin/python

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import os

@pytest.fixture(scope='session')
def urlBase():
    rt = os.getenv("URL_BASE")
    if rt:
        return rt
    return "http://10.8.3.94:8001"

@pytest.fixture(scope='session')
def user():
    rt = os.getenv("ACCOUNT")
    if rt:
        return rt
    return "root"

@pytest.fixture(scope='session')
def passwd():
    rt = os.getenv("PASSWD")
    if rt:
        return rt
    return "123456"

@pytest.fixture(scope='session')
def unauth():
    return '<html><title>403: Forbidden</title><body>403: Forbidden</body></html>'

@pytest.fixture(scope='session')
def driver(urlBase,user,passwd):
    u'''获取以及登录的浏览器'''
    with webdriver.Firefox() as driver:
        driver.get(urlBase+'/login')
        assert driver.title==u'故障定位系统'

        element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "normal_login_account")))
        
        driver.find_element_by_id('normal_login_account').send_keys('root')
        driver.find_element_by_id('normal_login_passwd').send_keys('123456')
        driver.find_element_by_tag_name('button').click()

        driver.maximize_window()
        
        yield driver

        driver.quit()